package com.aos.erp.schools.rest.student;

import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.schools.cutils.router.Rest;
import com.aos.erp.schools.model.student.StudentPicture;
import com.aos.erp.schools.model.student.StudentWarning;
import com.aos.erp.schools.model.student.ro.warnig.AddWarnigRo;
import com.aos.erp.schools.service.student.StudentWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: chb
 * @Date: 2018/11/1 19:22
 * @Description:    学员预警表
 */
@RestController
@RequestMapping(Rest.StudentWarning.ROOT)
@Api(tags = {"学员预警信息"})
public class StudentWarningController {

    @Autowired
    private StudentWarningService studentWarningService;


    @PostMapping(Rest.StudentWarning.add)
    @ApiOperation(value = "学员预警信息添加")
    public ResultEntity addStudentPicture(AddWarnigRo ro){

        try {
            StudentWarning sw=new StudentWarning();
            BeanUtils.copyProperties(ro,sw);
            studentWarningService.addBean(sw);
            return ResultEntity.success("学员预警信息添加成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("学员预警信息添加失败!");
        }

    }


    @PostMapping(Rest.StudentWarning.update)
    @ApiOperation(value = "学员预警信息修改")
    public ResultEntity updateStudentPicture(StudentWarning studentWarning){

           int row=studentWarningService.update(studentWarning);
           if(row>0)
           {
               return ResultEntity.success("学员资源修改成功!");
           }
           return ResultEntity.failed("学员资源修改失败!");
    }

    @PostMapping(Rest.StudentWarning.getByStudentId)
    @ApiOperation(value = "学员预警信息查询")
    @ApiImplicitParam(name = "studentId",value = "学员Id",required = true,dataType ="Long",paramType ="query" )
    public ResultEntity getByStudentId(Long studentId){

        try {
            List<StudentWarning> listSw=studentWarningService.getStudentById(studentId);
            return ResultEntity.success(listSw);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("学员资源查询失败!");
        }

    }
}
